<?php
class retrieve_webobjects extends retrieve_base{

	private $module_display_options 	= array(
		array("WEBOBJECTS_GET_THEMES",	"LOCALE_WEBOBJECTS_SET_THEME_CHANNEL"	),
		array("WEBOBJECTS_GET_CSS",		"LOCALE_WEBOBJECTS_SET_CSS_CHANNEL"		),
		array("WEBOBJECTS_GET_SIZE",	"LOCALE_WEBOBJECTS_SET_SIZE_CHANNEL"	)
	);

	/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();
		/**
		* Table structure for table 'web_objects'
		*/
		$fields = array(
			array("wo_identifier"		,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("wo_client"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wo_type"				,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wo_label"			,"varchar(255)"				,"NULL"		,"default ''"),
			array("wo_created"			,"datetime"					,"NULL"		,"default ''"),
			array("wo_command"			,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("wo_all_locations"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wo_set_inheritance"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wo_show_label"		,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wo_owner_module"		,"varchar(255)"				,"NULL"		,"default ''"),
			array("wo_owner_id"			,"unsigned integer"			,"NULL"		,"default ''"),
			array("wo_display"			,"unsigned integer"			,"NULL"		,"default '0'")
		);
		$primary = "wo_identifier";
		$tables[count($tables)] = array("web_objects",$fields,$primary);
		/**
		* Table structure for table 'web_container_to_layout' 
		*/
		$fields = array(
			array("wctl_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("wctl_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wctl_layout"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wctl_container"	,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wctl_position"	,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("wctl_rank"		,"unsigned integer"			,"NOT NULL"	,"default '0'")
		);
		$primary = "wctl_identifier";
		$tables[count($tables)] = array("web_container_to_layout",$fields,$primary);
		/**
		* Table structure for table 'web_objects_in_container' 
		*/
		$fields = array(
			array("woic_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("woic_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("woic_container"	,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("woic_object"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("woic_rank"		,"unsigned integer"			,"NOT NULL"	,"default '0'")
		);
		$primary = "woic_identifier";
		$tables[count($tables)] = array("web_objects_in_container",$fields,$primary);
		/**
		* Table structure for table 'web_objects_to_menu' 
		* replaced with MENU_TO_OBJECT table in LAYOUT MODULE
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		$fields = array(
			array("wotm_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("wotm_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wotm_menu"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wotm_object"		,"unsigned integer"			,"NOT NULL"	,"default '0'")
		);
		$primary = "wotm_identifier";
		$tables[count($tables)] = array("web_objects_to_menu",$fields,$primary);
		*/
		/**
		* Table structure for table 'web_layouts' a list of people that have subscribed
		* to a particular mailing list
		*/
		$fields = array(
			array("wol_identifier"		,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("wol_client"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wol_status"			,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wol_version"			,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wol_live"			,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wol_complete"		,"unsigned small integer"	,"NOT NULL"	,"default '1'"),
			array("wol_label"			,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("wol_layout_design"	,"varchar(4)"				,"NOT NULL"	,"default '1111'"),
			array("wol_all_locations"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wol_set_inheritance"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("wol_theme"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wol_created"			,"datetime"					,"NOT NULL"	,"default ''")
		);
		$primary = "wol_identifier";
		$tables[count($tables)] = array("web_layouts",$fields,$primary);
		/**
		* Table structure for table 'web_layout_to_menu' a list of people that have subscribed
		* to a particular mailing list
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		$fields = array(
			array("wor_identifier"		,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
			array("wor_client"			,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("wor_layout"			,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("wor_menu"			,"unsigned integer"	,"NOT NULL"	,"default '0'")
		);
		$primary = "wor_identifier";
		$tables[count($tables)] = array("web_layout_to_menu",$fields,$primary);
		*/
		/**
		* Table structure for table 'web_properties' a list of people that have subscribed
		* to a particular mailing list
		*/
		$fields = array(
			array("wop_identifier"		,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
			array("wop_client"			,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("wop_container_object","unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("wop_name"			,"varchar(255)"		,"NOT NULL"	,"default ''"),
			array("wop_value"			,"varchar(255)"		,"NOT NULL"	,"default ''")
		);
		$primary = "wop_identifier";
		$tables[count($tables)] = array("web_properties",$fields,$primary);
		/**
		* Table structure for table 'web_containers' a list of people that have subscribed
		* to a particular mailing list
		*/
		$fields = array(
			array("wc_identifier"			,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("wc_layout_identifier"	,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wc_client"				,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("wc_label"				,"varchar(255)"				,""			,"default ''"),
			array("wc_position"				,"varchar(255)"				,""			,"default ''"),
			array("wc_rank"					,"unsigned integer"			,""			,"default ''"),
			array("wc_layout_type"			,"unsigned small integer"	,""			,"default '0'"),
			array("wc_layout_columns"		,"unsigned integer"			,""			,"default '1'"),
			array("wc_name"					,"varchar(255)"				,""			,"default ''"),
			array("wc_width"				,"varchar(5)"				,""			,"default ''"),
			array("wc_created"				,"datetime"					,""			,"default ''"),
			array("wc_type"					,"varchar(255)"				,""			,"default '1'")
		);
		$primary = "wc_identifier";
		$tables[count($tables)] = array("web_containers",$fields,$primary);
		return $tables;
	}
	function create_client_details($parameters){
		$client_identifier = $this->check_parameters($parameters,"client_identifier",$this->client_identifier);
/*
		$length=count($this->parent->modules);
//		print "length $length";
		for($index=0;$index<$length;$index++){
			if ($this->parent->modules[$index]["table"]==1){
//				print $this->parent->modules[$index]["tag"]."MENU_DISPLAY_OPTIONS<br>";
				$this->call_command($this->parent->modules[$index]["tag"]."MENU_DISPLAY_OPTIONS",array(array(),1));
			}
		}*/

		$module_display_options_array = $this->call_command("ENGINE_RETRIEVE",array("MENU_DISPLAY_OPTIONS",array(array(),1)));
		//print_r( $module_display_options_array);
		$module_display_options="";
		$length_of_array=count($module_display_options_array);
		if ($this->module_debug){
			$this->call_command("UTILS_DEBUG_ENTRY",array($this->module_name,"length of display options",__LINE__,"$length_of_array"));
		}
		for($index=0;$index<$length_of_array;$index++){
			if (count($module_display_options_array[$index][1])>0){
				if ($module_display_options_array[$index][1]!=""){
					for($i=0;$i<count($module_display_options_array[$index][1]);$i++){
						if ($module_display_options_array[$index][1][$i][0]!=""){
							if ($module_display_options_array[$index][1][$i][0]=='PRESENTATION_DISPLAY'){
								$module_display_options_array[$index][1][$i][0]='PRESENTATION_DISPLAY_PAGE';
							}
							$sql ="insert into web_objects (wo_client, wo_type, wo_label, wo_command, wo_all_locations, wo_show_label) values 
							($client_identifier, 1, '".$this->get_constant($module_display_options_array[$index][1][$i][1])."', '".$module_display_options_array[$index][1][$i][0]."',0,0);";
							$this->db->query($sql);
						}
					}
				}
			}
		}
//$module_display_options
//			Array('Display the SiteMap','WEBOBJECTS_SHOW_SITEMAP_EXTRACT',1,0),
		$list = Array(
			Array('Display the Page Option buttons','WEBOBJECTS_SHOW_PRINTER_FRIENDLY',1,0),
			Array('Show Date (Todays)','WEBOBJECTS_SHOW_DATE',1,0),
			Array('Show Date (Site Last Updated)','WEBOBJECTS_SHOW_SITE_UPDATED_DATE',1,0),
//			Array('Show Date (page Updated)','WEBOBJECTS_SHOW_PAGE_UPDATED_DATE',1,0),
			Array('Show breadcrumb trail','WEBOBJECTS_SHOW_BREADCRUMB',1,0),
			Array('Show menu (primary)','WEBOBJECTS_SHOW_MAIN_MENU',1,0),
			Array('Show menu (secondary)','WEBOBJECTS_SHOW_SUB_MENU',1,0),
			Array('Show menu (footer format)','WEBOBJECTS_SHOW_TEXT_BASED_LEVEL_ONE_MENU',0,0),
			Array('Show Search in (column)','WEBOBJECTS_SHOW_SEARCH_BOX_COLUMN',1,0),
			Array('Show Search in (row)','WEBOBJECTS_SHOW_SEARCH_BOX_ROW',1,0),
			Array('Show Top of page option','WEBOBJECTS_SHOW_TOP_OF_PAGE',1,0)
		);
		if (($this->parent->server[LICENCE_TYPE]==ECMS)||($this->parent->server[LICENCE_TYPE]==MECM)){
			$list[count($list)] = Array('Show login form (default)','WEBOBJECTS_SHOW_LOGIN',1,0);
		}
		$m = count($list);
		for($i = 0 ; $i < $m ; $i ++ ){
			$sql = "insert into web_objects (wo_client,wo_type,wo_label,wo_command,wo_all_locations,wo_show_label) values ($client_identifier,2,'".$list[$i][0]."','".$list[$i][1]."',".$list[$i][2].",".$list[$i][3].");";
			$this->db->query($sql);
		}
		$m = count($this->module_display_options);
		for($i = 0 ; $i < $m ; $i ++ ){
			$sql = "insert into web_objects (wo_client,wo_type,wo_label,wo_command,wo_all_locations,wo_show_label) values ($client_identifier, 1, '".$this->get_constant($this->module_display_options[$i][1])."', '".$this->module_display_options[$i][0]."', 0, 0);";
			$this->db->query($sql);
		}
		return "";
	}	
}
?>